<?php

declare(strict_types=1);

namespace App\Service;

use App\Model\Driver as DriverModel;

class Driver extends BaseService
{
    // 分页列表
    public function list(array $map, int $page = 10)
    {
        return DriverModel::query()->with(['company:company_id,company_name'])->select('driver_id', 'company_id', 'sex', 'head_img', 'birthday', 'username', 'phone', 'status', 'created_at')->where($map)->orderBy('driver_id', 'desc')->paginate($page);
    }

    // 添加
    public function addDriver($data)
    {
        unset($data['id']);
        return DriverModel::insert($data);
    }

    // 获取用户详细信息
    public function detail($driver_id)
    {
        return DriverModel::query()->where('driver_id', $driver_id)->first();
    }

    // 编辑
    public function editDriver($id, $data)
    {
        return DriverModel::query()->where('id', $id)->update($data);
    }

    // 删除
    public function deleteDriver($driver_id)
    {
        return DriverModel::where('driver_id', $driver_id)->delete();
    }
}
